# @Time : 2024-10-25 9:38
# @Author : Fioman 
# @Phone : 13149920693
import numbers


class Group:
    def __init__(self, groupName, companyName, staffs):
        self.groupName = groupName
        self.companyName = companyName
        self.staffs = staffs

    def __str__(self):
        return f"组名: {self.groupName}, 公司名: {self.companyName},员工列表: {self.staffs}"

    def __contains__(self, item):
        if item in self.staffs:
            return True
        else:
            return False

    def __reversed__(self):
        # 注意这里的reverse() 和reversed(iterable)的区别.
        # reversed() 返回的是可迭代对象  而reverse()返回的就是列表
        self.staffs.reverse()

    def __getitem__(self, item):
        """
        :param item: item可以接收一个整数或者是一个切片对象
        :return:
        """
        cls = type(self)
        if isinstance(item, numbers.Integral):
            return cls(self.groupName, self.companyName, self.staffs[item])
        elif isinstance(item, slice):
            return cls(self.groupName, self.companyName, self.staffs[item])

    def __len__(self):
        return len(self.staffs)


staffs = ["Fioman", "Hammer", "YueYue"]
group = Group("Hengding", "user", staffs)
subGroup = group[:2]
print(subGroup, type(subGroup))
subGroup = group[0]
print(subGroup, type(subGroup))
print("group的长度为: {}".format(len(group)))

reversed(group)
print(f"group Reversed: {group}")
